<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title> computed </title>
</head>

<body>
    <div id="app">
        <div id="app">
            <p>First name:<input type="text" v-model="firstName"></p>
            <p>Last name:<input type="text" v-model="lastName"></p>
            <p>{{ fullName }}</p>
        </div>
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.0.2/vue.global.prod.js"></script>
    <script>
        const vm = Vue.createApp({
            data() {
                return {
                    firstName: 'Smith',
                    lastName: "Will"
                }
            },
            // 计算属性
            computed: {
                fullName: {
                    //getter
                    get() {
                        return this.firstName + ' ' + this.lastName;
                    },
                    //setter
                    set(newValue) {
                        let names = newValue.split(' ');
                        this.firstName = names[0];
                        this.lastName = names[1];
                    }
                }
            }
        }).mount(' #app');
    </script>
</body>

</html>